package com.ror.java.se.file;

//统计一个文件夹的总大小

import java.io.File;

public class Demo08 {
    public static void main(String[] args) {
        File dir = new File("assets", "file");
        System.out.println(sizeOf(dir));
    }

    static long sizeOf(File parent) {
        if (!parent.exists()) return -1;
        long len = 0;
        File[] children = parent.listFiles();
        if (children == null) return -1;
        for (File child : children) {
            if (child.isFile()) len += child.length();
            else len += sizeOf(child);
        }
        return len;
    }
}
